//
//  LoginController.swift
//  ExpressDriver
//
//  Created by sheng on 2017/11/7.
//  Copyright © 2017年 sheng. All rights reserved.
//

import UIKit
import SnapKit
import SlideMenuControllerSwift

class LoginController: UIViewController {
    
    @IBOutlet weak var logo: UIImageView!
    
    @IBOutlet weak var userInput: UITextField!
    
    @IBOutlet weak var passwordInput: UITextField!
    
    @IBOutlet weak var loginBtn: UIButton!
    
    @IBOutlet weak var checkbox: CheckBox!
    
    @IBOutlet weak var checkLabel: UILabel!
    
    var registerBtn: UIButton!
    
    

    override func viewDidLoad() {
        super.viewDidLoad()

        self.logo.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(self.view.snp.top).offset(120)
            make.centerX.equalTo(self.view)
            make.height.equalTo(80)
            make.width.equalTo(80)
        }
        
        
        let imgLock1 =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        imgLock1.image = UIImage(named:"user")
        self.userInput.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        self.userInput.leftViewMode = UITextFieldViewMode.always
        self.userInput.leftView!.addSubview(imgLock1)
        
        self.userInput.snp.makeConstraints { (make) -> Void in
            make.left.equalTo(30)
            make.right.equalTo(-30)
            make.height.equalTo(40)
            make.top.equalTo(self.logo.snp.bottom).offset(40)
        }
        
        let imgLock2 =  UIImageView(frame:CGRect(x: 9, y: 9, width: 22, height: 22))
        imgLock2.image = UIImage(named:"password")
        self.passwordInput.leftView = UIView(frame:CGRect(x: 0, y: 0, width: 40, height: 40))
        self.passwordInput.leftViewMode = UITextFieldViewMode.always
        self.passwordInput.leftView!.addSubview(imgLock2)
        
        self.passwordInput.snp.makeConstraints { (make) -> Void in
            make.left.equalTo(30)
            make.right.equalTo(-30)
            make.height.equalTo(40)
            make.top.equalTo(self.userInput.snp.bottom).offset(10)
        }
        
        
        self.loginBtn.layer.cornerRadius = 5
        self.loginBtn.layer.borderWidth = 0.5
        self.loginBtn.layer.borderColor = UIColor.lightGray.cgColor
        self.loginBtn.backgroundColor = UIColor.white
        
        self.loginBtn.snp.makeConstraints { (make) -> Void in
            make.height.equalTo(40)
            make.left.equalTo(60)
            make.right.equalTo(-60)
            make.top.equalTo(self.checkbox.snp.bottom).offset(20)
        }
        
        self.checkbox.snp.makeConstraints { (make) -> Void in
            make.height.equalTo(22)
            make.width.equalTo(22)
            make.left.equalTo(30)
            make.top.equalTo(self.passwordInput.snp.bottom).offset(8)
        }
        
        self.checkLabel.snp.makeConstraints { (make) -> Void in
            make.centerY.equalTo(self.checkbox)
            make.left.equalTo(60)
        }
        
        
        registerBtn = UIButton()
        registerBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        registerBtn.setTitle("Register", for: UIControlState())
        registerBtn.setTitleColor(UIColor.black, for: UIControlState())
        registerBtn.layer.borderColor = UIColor.lightGray.cgColor
        registerBtn.layer.borderWidth = 0.5
        registerBtn.layer.cornerRadius = 5
        registerBtn.addTarget(self, action: #selector(register), for: .touchUpInside)
        self.view.addSubview(registerBtn)
        registerBtn.snp.makeConstraints { (make) in
            make.bottom.equalTo(self.view.snp.bottom).offset(-15)
            make.centerX.equalTo(self.view)
            make.width.height.equalTo(loginBtn)
            
        }
        
        
        //https://101.127.215.108/svn/SEDS_Product_MerchantLogisticCompany_AndroidIOS/trunk
        //https://101.127.215.108/svn/SEDS_Product_DriverIOS/trunk
    }

    
    
    func register(_ sender: UIButton) {
        
        let registerController = RegisterController()
        registerController.title = "Register"
        let nav = UINavigationController(rootViewController: registerController)
        present(nav, animated: true, completion: nil)
        
    }
    
    
    @IBAction func login(_ sender: UIButton) {
        
        let menuController = MenuViewController()
        let homeController = HomeController()
        homeController.title = "Home"
        let nav: UINavigationController = UINavigationController(rootViewController: homeController)
        let drawerController =  DrawerViewController(mainVC: nav, leftMenuVC: menuController, leftWidth: 230)
        present(drawerController, animated: true, completion: nil)
        
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //http://www.jianshu.com/p/367952852c6d
    //http://blog.csdn.net/baixiaozhe/article/details/48974497
    //https://github.com/kishikawakatsumi/BookReader
    //https://www.ctolib.com/swift/
    //https://github.com/Alua-Kinzhebayeva/iOS-PDF-Reader

    

}
